package com.hejian.android.a72ggametools.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hejian.android.a72ggametools.R;
import com.hejian.android.a72ggametools.bean.GameComment;
import com.hejian.android.a72ggametools.viewholder.GameCommentViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/1/19.
 */
public class GameCommentAdapter extends BaseAdapter {
    private List<GameComment> gameCommentList;
    private Context context;

    public GameCommentAdapter(List<GameComment> gameCommentList, Context context) {
        this.gameCommentList = gameCommentList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return gameCommentList.size();
    }

    @Override
    public Object getItem(int position) {
        return gameCommentList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        GameCommentViewHolder gameCommentViewHolder;
        View view = convertView;
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.game_comment_item, null);
            gameCommentViewHolder = new GameCommentViewHolder();
            gameCommentViewHolder.nickName = (TextView) view.findViewById(R.id.game_comment_nickname);
            gameCommentViewHolder.content = (TextView) view.findViewById(R.id.game_comment_content);
            gameCommentViewHolder.pubdata = (TextView) view.findViewById(R.id.game_comment_pubdate);
            view.setTag(gameCommentViewHolder);
        } else {
            gameCommentViewHolder = (GameCommentViewHolder) view.getTag();
        }
        gameCommentViewHolder.nickName.setText(gameCommentList.get(position).getNickName());
        gameCommentViewHolder.content.setText(gameCommentList.get(position).getContent());
        gameCommentViewHolder.pubdata.setText(gameCommentList.get(position).getPubdata());
        return view;
    }
}
